package com.bestdreamer.tcp.demo2;

import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.net.Socket;

public class ClientThread implements Runnable{

    // 该线程负责处理 Socket
    private final Socket s;
    // 该线程所处理的 Socket 对应的输入流
    private BufferedReader br = null;
    public ClientThread(Socket s)throws IOException{
        this.s = s;
        br = new BufferedReader(new InputStreamReader(s.getInputStream()));
    }

    @Override
    public void run() {
        try{
            String content = null;
            // 不断地读取 Socket 输入流中的内容，并将这些内容打印输出
            while ((content = br.readLine()) != null){
                System.out.println(content);
            }
        }catch (Exception e){
            e.printStackTrace();
        }
    }
}
